package lumis.portal.dao;

import lumis.portal.PortalException;
import lumis.portal.authentication.AuthenticationDaoJdbc;
import lumis.portal.authentication.IAuthenticationDao;
import lumis.portal.channel.ChannelDaoJdbc;
import lumis.portal.channel.IChannelDao;
import lumis.portal.channel.tree.ChannelTreeDaoJdbc;
import lumis.portal.channel.tree.IChannelTreeDao;
import lumis.portal.clock.ClockDaoJdbc;
import lumis.portal.clock.IClockDao;
import lumis.portal.css.CssDaoJdbc;
import lumis.portal.css.ICssDao;
import lumis.portal.file.FileDaoJdbc;
import lumis.portal.file.FilesDaoJdbc;
import lumis.portal.file.IFileDao;
import lumis.portal.file.IFilesDao;
import lumis.portal.localization.CustomStringLocalizationDaoJdbc;
import lumis.portal.localization.ICustomStringLocalizationDao;
import lumis.portal.localization.IStringLocalizationDao;
import lumis.portal.localization.MainStringLocalizationDaoXml;
import lumis.portal.metatag.IMetaTagDao;
import lumis.portal.metatag.MetaTagDao;
import lumis.portal.page.IPageDao;
import lumis.portal.page.PageDaoHib;
import lumis.portal.page.link.IPageLinkDao;
import lumis.portal.page.link.PageLinkDaoJdbc;
import lumis.portal.principal.IPrincipalDao;
import lumis.portal.principal.PrincipalDaoJdbc;
import lumis.portal.sendmail.dao.ISendMailDao;
import lumis.portal.sendmail.dao.hibernate.SendMailDaoHib;
import lumis.portal.service.IServiceDao;
import lumis.portal.service.ServiceDaoHib;
import lumis.portal.service.type.IServiceTypeDao;
import lumis.portal.service.type.ServiceTypeDaoJdbc;
import lumis.portal.serviceinstance.IServiceInstanceDao;
import lumis.portal.serviceinstance.ServiceInstanceDaoHib;
import lumis.portal.serviceinterface.IServiceInterfaceDao;
import lumis.portal.serviceinterface.ServiceInterfaceDaoHib;
import lumis.portal.serviceinterface.list.IServiceInterfaceListDao;
import lumis.portal.serviceinterface.list.ServiceInterfaceListDaoJdbc;
import lumis.portal.serviceinterface.menu.IServiceInterfaceMenuGroupTypeDao;
import lumis.portal.serviceinterface.menu.IServiceInterfaceMenuItemTypeDao;
import lumis.portal.serviceinterface.menu.ServiceInterfaceMenuGroupTypeDaoHib;
import lumis.portal.serviceinterface.menu.ServiceInterfaceMenuItemTypeDaoHib;
import lumis.portal.serviceinterface.style.IServiceInterfaceStyleDao;
import lumis.portal.serviceinterface.style.ServiceInterfaceStyleDaoJdbc;
import lumis.portal.serviceinterface.type.IServiceInterfaceTypeDao;
import lumis.portal.serviceinterface.type.ServiceInterfaceTypeDaoJdbc;
import lumis.portal.serviceinterfaceinstance.IServiceInterfaceInstanceDao;
import lumis.portal.serviceinterfaceinstance.ServiceInterfaceInstanceDaoJdbc;
import lumis.portal.user.IUserDao;
import lumis.portal.user.UserDaoJdbc;
import lumis.portal.xslcache.IXslCacheDao;
import lumis.portal.xslcache.XslCacheDaoJdbc;
import lumis.upgrade.IUpgradeDao;
import lumis.upgrade.UpgradeDaoJdbc;
import lumis.util.security.acl.AccessControlDaoJdbc;
import lumis.util.security.acl.IAccessControlDao;

/**
 * Creates all Dao objects.
 * 
 * @version $Revision: 9647 $ $Date: 2008-08-06 16:37:36 -0300 (Wed, 06 Aug 2008) $
 * @since 4.0.0
 */
public class DaoFactory
{
	// singletons
	private static IChannelDao channelDao = null;
	private static IPageDao pageDao = null;
	private static IServiceDao serviceDao = null;
	private static IServiceInstanceDao serviceInstanceDao = null;
	private static IServiceInterfaceDao serviceInterfaceDao = null;
	private static IServiceInterfaceInstanceDao serviceInterfaceInstanceDao = null;
	private static IAuthenticationDao authenticationDao = null;
	private static IStringLocalizationDao mainStringLocalizationDao = null;
	private static ICustomStringLocalizationDao customStringLocalizationDao = null;
	private static IChannelTreeDao channelTreeDao = null;
	private static IServiceInterfaceListDao serviceInterfaceListDao = null;
	private static IUserDao userDao = null;
	private static IAccessControlDao accessControlDao = null;
	private static IPrincipalDao principalDao = null;
	private static IServiceTypeDao serviceTypeDao = null;
	private static IServiceInterfaceTypeDao serviceInterfaceTypeDao = null;
	private static IServiceInterfaceStyleDao serviceInterfaceStyleDao = null;
	private static ICssDao cssDao = null;
	private static IClockDao clockDao = null;
	private static IUpgradeDao upgradeDao = null;
	private static IPageLinkDao pageLinkDao = null;
	private static IServiceInterfaceMenuGroupTypeDao serviceInterfaceMenuGroupTypeDao = null;
	private static IServiceInterfaceMenuItemTypeDao serviceInterfaceMenuItemTypeDao = null;
	private static IXslCacheDao xslCacheDao = null;
	private static IFileDao fileDao = null;
	private static IFilesDao filesDao = null;
	private static ISendMailDao sendMailDao = null;	
	private static IMetaTagDao metaTagDao = null;

	public static IChannelDao getChannelDao() throws DaoException, PortalException
	{
		if (channelDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (channelDao == null)
					channelDao = new ChannelDaoJdbc();
			}
		}

		return channelDao;
	}

	public static IPageDao getPageDao() throws DaoException, PortalException
	{
		if (pageDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (pageDao == null)
					pageDao = new PageDaoHib();
			}
		}

		return pageDao;
	}

	public static IServiceDao getServiceDao() throws DaoException, PortalException
	{
		if (serviceDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceDao == null)
					serviceDao = new ServiceDaoHib();
			}
		}

		return serviceDao;
	}

	public static IServiceInstanceDao getServiceInstanceDao() throws DaoException, PortalException
	{
		if (serviceInstanceDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInstanceDao == null)
					serviceInstanceDao = new ServiceInstanceDaoHib();
			}
		}

		return serviceInstanceDao;
	}

	public static IServiceInterfaceDao getServiceInterfaceDao() throws DaoException, PortalException
	{
		if (serviceInterfaceDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceDao == null)
					serviceInterfaceDao = new ServiceInterfaceDaoHib();
			}
		}

		return serviceInterfaceDao;
	}

	public static IServiceInterfaceInstanceDao getServiceInterfaceInstanceDao() throws DaoException, PortalException
	{
		if (serviceInterfaceInstanceDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceInstanceDao == null)
					serviceInterfaceInstanceDao = new ServiceInterfaceInstanceDaoJdbc();
			}
		}

		return serviceInterfaceInstanceDao;
	}

	public static IAuthenticationDao getAuthenticationDao() throws DaoException, PortalException
	{
		if (authenticationDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (authenticationDao == null)
					authenticationDao = new AuthenticationDaoJdbc();
			}
		}

		return authenticationDao;
	}

	public static IStringLocalizationDao getMainStringLocalizationDao() throws DaoException, PortalException
	{
		if (mainStringLocalizationDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (mainStringLocalizationDao == null)
					mainStringLocalizationDao = new MainStringLocalizationDaoXml();
			}
		}

		return mainStringLocalizationDao;
	}

	public static ICustomStringLocalizationDao getCustomStringLocalizationDao() throws DaoException, PortalException
	{
		if (customStringLocalizationDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (customStringLocalizationDao == null)
					customStringLocalizationDao = new CustomStringLocalizationDaoJdbc();
			}
		}

		return customStringLocalizationDao;
	}

	public static IChannelTreeDao getChannelTreeDao() throws DaoException, PortalException
	{
		if (channelTreeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (channelTreeDao == null)
					channelTreeDao = new ChannelTreeDaoJdbc();
			}
		}

		return channelTreeDao;
	}
	
	public static IServiceInterfaceListDao getServiceInterfaceListDao() throws DaoException, PortalException
	{
		if (serviceInterfaceListDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceListDao == null)
					serviceInterfaceListDao = new ServiceInterfaceListDaoJdbc();
			}
		}

		return serviceInterfaceListDao;
	}

	public static IUserDao getUserDao() throws DaoException, PortalException
	{
		if (userDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (userDao == null)
					userDao = new UserDaoJdbc();
			}
		}

		return userDao;
	}

	public static IAccessControlDao getAccessControlDao() throws DaoException, PortalException
	{
		if (accessControlDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (accessControlDao == null)
					accessControlDao = new AccessControlDaoJdbc();
			}
		}

		return accessControlDao;
	}
	
	public static IPrincipalDao getPrincipalDao() throws DaoException, PortalException
	{
		if (principalDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (principalDao == null)
					principalDao = new PrincipalDaoJdbc();
			}
		}

		return principalDao;
	}
	
	public static IServiceTypeDao getServiceTypeDao() throws DaoException, PortalException
	{
		if (serviceTypeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceTypeDao == null)
					serviceTypeDao = new ServiceTypeDaoJdbc();
			}
		}

		return serviceTypeDao;
	}
	
	public static IServiceInterfaceTypeDao getServiceInterfaceTypeDao() throws DaoException, PortalException
	{
		if (serviceInterfaceTypeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceTypeDao == null)
					serviceInterfaceTypeDao = new ServiceInterfaceTypeDaoJdbc();
			}
		}

		return serviceInterfaceTypeDao;
	}
	
	public static IServiceInterfaceStyleDao getServiceInterfaceStyleDao() throws DaoException, PortalException
	{
		if (serviceInterfaceStyleDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceStyleDao == null)
					serviceInterfaceStyleDao = new ServiceInterfaceStyleDaoJdbc();
			}
		}

		return serviceInterfaceStyleDao;
	}
	
	public static ICssDao getCssDao() throws DaoException, PortalException
	{
		if (cssDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (cssDao == null)
					cssDao = new CssDaoJdbc();
			}
		}

		return cssDao;
	}
	
	public static IMetaTagDao getMetaTagDao() throws DaoException, PortalException
	{
		if (metaTagDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (metaTagDao == null)
					metaTagDao = new MetaTagDao();
			}
		}

		return metaTagDao;
	}
	
	public static IClockDao getClockDao() throws DaoException, PortalException
	{
		if (clockDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (clockDao == null)
					clockDao = new ClockDaoJdbc();
			}
		}

		return clockDao;
	}
	
	public static IUpgradeDao getUpgradeDao() throws DaoException, PortalException
	{
		if (upgradeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (upgradeDao == null)
					upgradeDao = new UpgradeDaoJdbc();
			}
		}

		return upgradeDao;
	}
	
	public static IPageLinkDao getPageLinkDao() throws DaoException, PortalException
	{
		if (pageLinkDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (pageLinkDao == null)
					pageLinkDao = new PageLinkDaoJdbc();
			}
		}

		return pageLinkDao;
	}
	
	
	public static IServiceInterfaceMenuGroupTypeDao getServiceInterfaceMenuGroupTypeDao() throws DaoException, PortalException
	{
		if (serviceInterfaceMenuGroupTypeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceMenuGroupTypeDao == null)
					serviceInterfaceMenuGroupTypeDao = new ServiceInterfaceMenuGroupTypeDaoHib();
			}
		}

		return serviceInterfaceMenuGroupTypeDao;
	}
	
	public static IServiceInterfaceMenuItemTypeDao getServiceInterfaceMenuItemTypeDao() throws DaoException, PortalException
	{
		if (serviceInterfaceMenuItemTypeDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (serviceInterfaceMenuItemTypeDao == null)
					serviceInterfaceMenuItemTypeDao = new ServiceInterfaceMenuItemTypeDaoHib();
			}
		}

		return serviceInterfaceMenuItemTypeDao;
	}
	
	public static IXslCacheDao getXslCacheDao() throws DaoException, PortalException
	{
		if (xslCacheDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (xslCacheDao == null)
					xslCacheDao = new XslCacheDaoJdbc();
			}
		}
		
		return xslCacheDao;
	}

	public static IFileDao getFileDao() throws DaoException, PortalException
	{
		if (fileDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (fileDao == null)
					fileDao = new FileDaoJdbc();
			}
		}

		return fileDao;
	}

	public static IFilesDao getFilesDao() throws DaoException, PortalException
	{
		if (filesDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (filesDao == null)
					filesDao = new FilesDaoJdbc();
			}
		}

		return filesDao;
	}

	/**
	 * Returns the SendMailDao.
	 * @return the SendMailDao.
	 * @since 4.0.4
	 */
	public static ISendMailDao getSendMailDao() throws DaoException, PortalException
	{
		if (sendMailDao == null)
		{
			synchronized (DaoFactory.class)
			{
				if (sendMailDao == null)
					sendMailDao = new SendMailDaoHib();
			}
		}

		return sendMailDao;
	}
}
